﻿using System;
using System.Windows.Forms;

namespace FileWatch
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private string message = "{0}：文件 {1} {2}\r\n";
        private void Form1_Load(object sender, EventArgs e)
        {
            if (fbd1.ShowDialog() == DialogResult.OK)
            {

                fSW.Path = fbd1.SelectedPath;
            }
            else
            {
                Close();
            }

        }

        private void fSW_Changed(object sender, System.IO.FileSystemEventArgs e)
        {
            //文件更改

            rBox.AppendText(string.Format(message, DateTime.Now.ToLocalTime().ToString(), e.Name, "被更改"));

        }

        private void fSW_Created(object sender, System.IO.FileSystemEventArgs e)
        {
            //文件创建
            rBox.AppendText(string.Format(message, DateTime.Now.ToLocalTime().ToString(), e.Name, "被创建"));
        }

        private void fSW_Deleted(object sender, System.IO.FileSystemEventArgs e)
        {
            //文件删除
            rBox.AppendText(string.Format(message, DateTime.Now.ToLocalTime().ToString(), e.Name, "被删除"));
        }

        private void fSW_Renamed(object sender, System.IO.RenamedEventArgs e)
        {
            //文件重命名
            rBox.AppendText(string.Format(message, DateTime.Now.ToLocalTime().ToString(), e.Name, "被重命名"));

        }
    }
}
